#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <queue>
#include <stack>
#include <vector>
#include <iostream>
using namespace std;
#define MAX_SIZE 101
#define MY_MAX(x,y) ((x)>(y)?(x):(y))
typedef struct Vnode *PtrToV;
struct Vnode
{
    int id;
    PtrToV Near;
};
typedef struct LGraph
{
    PtrToV Near;
} AdjList[MAX_SIZE];
int compare(const void *a, const void *b)
{
    return *(int *)a - *(int *)b;
}

int main()
{
    int N, M, v1, v2, cost, temp_v;
    int num_V = 0;//all node num
    int In_degree[MAX_SIZE], Cost[MAX_SIZE], ALLCOST[MAX_SIZE][MAX_SIZE];
    AdjList LGraph;
    PtrToV NewNode;

    scanf("%d %d", &N, &M);
    for (int i = 0; i < N;i++)
    {
        In_degree[i] = 0;
        Cost[i] = 0;
        LGraph[i].Near = NULL;
    }
    queue<int> myqueue;
    for (int i = 0; i < M; i++)
    {
        scanf("%d %d %d", &v1, &v2, &cost);
        In_degree[v2]++;
        ALLCOST[v1][v2] = cost;
        // Cost[v2] = MY_MAX(Cost[v1] + cost, Cost[v2]);

        //有向图
        NewNode = (PtrToV)malloc(sizeof(Vnode));
        NewNode->id = v2;
        NewNode->Near = LGraph[v1].Near;
        LGraph[v1].Near = NewNode;
    }

    for (int i = 0; i < N; i++)
        if(In_degree[i]==0)
            myqueue.push(i);

    while(!myqueue.empty())
    {
        v1 = myqueue.front();
        myqueue.pop();
        num_V++;
        NewNode = (PtrToV)malloc(sizeof(Vnode));
        NewNode = LGraph[v1].Near;
        while(NewNode!=NULL)
        {
            v2 = NewNode->id;
            
            if(--In_degree[v2]==0)
                myqueue.push(v2);

            Cost[v2] = MY_MAX(Cost[v1] + ALLCOST[v1][v2], Cost[v2]);
            NewNode = NewNode->Near;
        }
    }
    if(num_V == N)
    {
        qsort(Cost, N, sizeof(int), compare);
        printf("%d", Cost[N - 1]);
    }
    else
        printf("Impossible");
    return 0;
}